var http_request = false;
function makePOSTRequest(url, parameters) {
	http_request = false;
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			// set type accordingly to anticipated content type
			//http_request.overrideMimeType('text/xml');
			http_request.overrideMimeType('text/html');
		}
	} else if (window.ActiveXObject) { // IE
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}
	if (!http_request) {
		alert('Cannot create XMLHTTP instance');
		return false;
	}
      
	http_request.onreadystatechange = alertContents;
	http_request.open('POST', url, true);
	http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http_request.setRequestHeader("Content-length", parameters.length);
	http_request.setRequestHeader("Connection", "close");
	http_request.send(parameters);
}

/* funcao importante */
function executaScript(val){
	var objScript = document.createElement("script");
	ini = val.indexOf('<script>');
	fim = val.indexOf('</script>', ini);
	codigo = val.substring(ini+8,fim);
	objScript.text = codigo;
	document.body.appendChild(objScript);
}
/**/
function alertContents() {
	if (http_request.readyState == 4) {
		if (http_request.status == 200) {
			//alert(http_request.responseText);
			result = http_request.responseText;
	// linha iportante 
	/* --> */ if(result.indexOf('<script>')!=-1) executaScript(result);
			document.getElementById('processos').innerHTML = result;            
		} else {
			alert('There was a problem with the request.');
		}
	}
}
/*
function get(obj) {
	var poststr = "mytextarea1=" + encodeURI( document.getElementById("mytextarea1").value ) +
					"&mytextarea2=" + encodeURI( document.getElementById("mytextarea2").value );
	makePOSTRequest('post.php', poststr);
}
*/
/* USUARIO */
function CadastraUsuario() {
	var poststr = "nome="+encodeURI( document.getElementById("nome").value) +
					"&login="+encodeURI( document.getElementById("login").value)+
					"&senha="+encodeURI( document.getElementById("senha").value)+
					"&nivel="+encodeURI( document.getElementById("nivel").value);
	makePOSTRequest('../control/usuario.php?exec=cadastrar_usuario', poststr);
}
function RemoverUsuario(v){
	if(confirm("Deseja realmente remover?")){
		DisableSelects();
		HabilitaDivFundo();
		var poststr = "id="+v;
		makePOSTRequest('../control/usuario.php?exec=remover_usuario', poststr);	
	}
}
function MudarStatusUsuario(v){
	DisableSelects();
	HabilitaDivFundo();
	var poststr = "id="+v;
	makePOSTRequest('../control/usuario.php?exec=mudar_status_usuario', poststr);
}
function MudarNivelUsuario(v){
	DisableSelects();
	HabilitaDivFundo();
	var poststr = "id="+v;
	makePOSTRequest('../control/usuario.php?exec=mudar_nivel_usuario', poststr);	
}
/* FIM USUARIO */


